package com.feini.ktv.svc.controller.pm;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feini.ktv.svc.entity.om.OmBox;
import com.feini.ktv.svc.entity.pm.PmBox;
import com.feini.ktv.svc.service.om.IOmBoxService;
import com.feini.ktv.svc.service.pm.IPmBoxService;
import com.podara.skeleton.controller.SkeletonController;
import com.podara.skeleton.log.annotation.LogLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jiangzr
 * @since 2021-04-13
 */
@LogLogger
@RestController
public class PmBoxController implements SkeletonController {
    @Autowired
    private IPmBoxService boxService;

    @Autowired
    private IOmBoxService omBoxService;

    @GetMapping("/boxList/{boxType}")
    public List<PmBox> boxList(@PathVariable("boxType") String boxType) {
        QueryWrapper<PmBox> boxMap = new QueryWrapper<PmBox>();
        boxMap.eq("box_type", boxType);
        List<PmBox> boxList = this.boxService.list(boxMap);
        if (null != boxList && boxList.size() > 0) {
            for (PmBox box : boxList) {
                QueryWrapper<OmBox> qryBox = new QueryWrapper<OmBox>();
                qryBox.eq("box_id", box.getBoxId());
                List<OmBox> omBoxList = omBoxService.list(qryBox);
                if (null != omBoxList && omBoxList.size() > 0) {
                    box.setStatus("1");
                }
            }
        }
        return boxList;
    }
}

